package com.wisewin.circle.api.controller;

import com.wisewin.circle.api.controller.base.BaseController;
import com.wisewin.circle.config.dto.ResultDTO;
import com.wisewin.circle.config.dto.ResultDTOBuilder;
import com.wisewin.circle.entity.LoginUser;
import com.wisewin.circle.entity.db.FeedbackDO;
import com.wisewin.circle.service.FeedbackService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/feedback")
public class FeedbackController extends BaseController {
    @Autowired
    private FeedbackService feedbackService;

    // 添加帮助与反馈信息
    @PostMapping("/addFeedback")
    public ResultDTO addFeedback (HttpServletRequest request, @RequestBody FeedbackDO feedbackDO) {
        String token = request.getHeader("token");
        if(StringUtils.isEmpty(token)){
            return ResultDTOBuilder.failure("0000005", "必传参数为空", null);
        }
        // 获取登录用户
        LoginUser loginUser = super.getLoginUser(token);
        if (loginUser == null ) { // 判断是否登录
            return ResultDTOBuilder.failure("0000001", "登录已过期", null);
        }
        feedbackDO.setUserId(loginUser.getId());
        return feedbackService.addFeedback(feedbackDO);
    }
}
